<?php

class Admin_HotelController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        $this->_helper->layout()->disableLayout();
        Zend_Loader::loadFile('../application/admin/models/Hotel.php');
        $hotel_model = new Hotel();
        $Hotel_arr = $hotel_model->listHotels();
        $this->view->Hotel_arr = $Hotel_arr;     
    }

    public function addAction()
    {
        $this->_helper->layout()->disableLayout();
		Zend_Loader::loadFile('../application/admin/forms/Hotel.php');
		Zend_Loader::loadFile('../application/admin/models/Hotel.php');
		Zend_Loader::loadFile('../application/default/models/Common.php');
		$controller = $this->getRequest()->getControllerName();
		$action = $this->getRequest()->getActionName();
        $options = array("action"=>$action);
        $hotel_form = new Form_Hotel($options);
        $mod_common = new Common();
        $this->view->hotel_form = $hotel_form;
        $this->view->title = "Add hotel details";
        $country_arr = $mod_common->getCountries();
        $this->view->country_arr = $country_arr;
    }
    
    public function doaddhotelAction()
	{
		Zend_Loader::loadFile('../application/admin/forms/Hotel.php');
		Zend_Loader::loadFile('../application/admin/models/Hotel.php');
		$form_hotel = new Form_Hotel();
		$hotel_model = new Hotel();
		$request = $this->getRequest();
		if ($request->isPost()) {            			
			$form_values = $request->getPost();
			$add_hotel = $hotel_model->addHotel($form_values);
		}
		
		exit;
	}

    public function editAction()
    {
    	$this->_helper->layout()->disableLayout();
        Zend_Loader::loadFile('../application/admin/forms/Hotel.php');
        Zend_Loader::loadFile('../application/admin/models/Hotel.php');
        Zend_Loader::loadFile('../application/default/models/Common.php');
        
        $hotel_model = new Hotel();
        $mod_common = new Common();
        $controller = $this->getRequest()->getControllerName();
		$action = $this->getRequest()->getActionName();
		$hotel_id = $this->_getParam('hotel_id', 0);		
		$options = array("action"=>$action, "hotel_id"=>$hotel_id);
        $hotel_form = new Form_Hotel($options);
        $this->view->hotel_form = $hotel_form;        
        $country_arr = $mod_common->getCountries();
        foreach ($country_arr as $country_entry) :
        	$city_arr = $mod_common->getCity($country_entry['country_id']);	
        	$this->view->city_arr = $city_arr;
        endforeach;
        
        $this->view->country_arr = $country_arr;
        
        
        $hotel_arr = $hotel_model->getHotel($hotel_id);
        
        $this->view->hotel_id = $hotel_id;
        if ($hotel_id > 0) {            
            //$hotel_form->populate($hotel_model->getHotel($hotel_id));    
            $this->view->hotel_arr = $hotel_arr;   
        }
        
    }

    public function doupdatehotelAction()
    {
    	Zend_Loader::loadFile('../application/admin/forms/Hotel.php');
		Zend_Loader::loadFile('../application/admin/models/Hotel.php');
		$form_hotel = new Form_Hotel();
		$hotel_model = new Hotel();
		$request = $this->getRequest();
		if ($request->isPost()) {            			
			$form_values = $request->getPost();
			$update_hotel = $hotel_model->updateHotel($form_values);
		}
		
		exit;
    }
    
    public function deleteAction()
    {
        $this->_helper->layout()->disableLayout();
    	Zend_Loader::loadFile('../application/admin/models/Hotel.php');
        $hotel_model = new Hotel();
        $hotel_id = $this->_getParam('h_id', 0);
        $hotel_model->deleteHotel($hotel_id);
        exit;
    }	  
		  
 	public function addamenityAction()
 	{
 		$this->_helper->layout()->disableLayout();
    	Zend_Loader::loadFile('../application/admin/models/Hotel.php');
        $hotel_model = new Hotel();
        $hotel_id = $this->_getParam('h_id', 0);
        $amenity_arr = $hotel_model->getAminities();
        $hotel_amenity_arr = $hotel_model->getAmenitiesByHotelId($hotel_id);
        $this->view->amenity_arr = $amenity_arr;
        $this->view->hotel_amenity_arr = $hotel_amenity_arr;
        $this->view->hotel_id = $hotel_id;
        $output_str = "";
        return $output_str;
        exit;
 	}
 	
 	public function doaddamenityAction()
 	{
 		$this->_helper->layout()->disableLayout();
    	Zend_Loader::loadFile('../application/admin/models/Hotel.php');
        $hotel_model = new Hotel();
        $hotel_id = $this->_getParam('hotel_id', 0);
        $request = $this->getRequest();
		if ($request->isPost()) {            			
			$form_values = $request->getPost();
			$assign_amenity = $hotel_model->assignAmenity($form_values, $hotel_id);
		}
		exit;
 	}
 	
 	public function addimageAction() 
 	{
 		$this->_helper->layout()->disableLayout();
    	Zend_Loader::loadFile('../application/admin/models/Hotel.php');
    	$hotel_model = new Hotel();        
        $request = $this->getRequest();
        $hotelid = $request->getParam('hotel_id');
        $this->view->hotelid = $hotelid;
 	}
 	
 	public function doaddimageAction()
 	{
 		$this->_helper->layout()->disableLayout();
 		Zend_Loader::loadFile('../application/admin/models/AddImage.php'); 		
 		$mod_img = new AddImage();
 		$hotelid = $this->_getParam('txtHotelId',0);
 		$files = $_FILES;
 		$add_hotel_images = $mod_img->uploadHotelImages($files, $hotelid); 		
 		exit;
 	}
}